package com.situ.mvc.controller;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.situ.mvc.common.ServerResponse;
import com.situ.mvc.entity.Role;
import com.situ.mvc.service.IRoleService;
import com.situ.mvc.service.impl.RoleServiceImpl;

@Controller
@RequestMapping(value = "/role")
public class RoleController {
	
	private IRoleService roleService = new RoleServiceImpl();
	
	@RequestMapping(value = "/getRolePageList")
	public String getRolePageList(){
		return "role_list";
	}
	
	@RequestMapping(value = "/getRoleList")
	@ResponseBody
	public ServerResponse getRoleList(Integer page,Integer limit){
		ServerResponse response = roleService.getRoleList(page,limit);
		return response;
	}
	
	@RequestMapping(value = "/deleteById")
	@ResponseBody
	public ServerResponse deleteById(Integer id){
		ServerResponse response = roleService.deleteById(id);
		return response;
	}
	
	@RequestMapping(value = "/toUpdate")
	public String toUpdate(Integer id,Model model){
		Role role = roleService.toUpdate(id);
		model.addAttribute("role", role);
		return "role_update";
	}
	
	@RequestMapping(value = "/roleUpdate")
	@ResponseBody
	public ServerResponse roleUpdate(Role role){
		ServerResponse response = roleService.roleUpdate(role);
		return response;
	}
	
	@RequestMapping(value = "/getAddRolePage")
	public String getAddRolePage(){
		return "role_add";
	}
	
	@RequestMapping(value = "/roleAdd")
	@ResponseBody
	public ServerResponse roleAdd(Role role){
		ServerResponse response = roleService.roleAdd(role);
		return response;
	}
	
	@RequestMapping(value = "/deleteAll")
	@ResponseBody
	public ServerResponse deleteAll(String ids){
		ServerResponse response = roleService.deleteAll(ids);
		return response;
	}
}
